DeriveGamemode("RPDM_BASE")

GM.Name 	= "RPDM"
GM.Author 	= "partyvan"

//Data Table indexes
DT_INT_MONEY 	= 0
DT_INT_UPGRADE 	= 1
DT_BOOL_AFK		= 0
DT_ENTITY_OWNER = 0

local nocollide = {
	"drug_random",
	"drug_booze",
	"drug_druglabdrug"
}
function GM:ShouldCollide(ent1, ent2)
	if ent1:IsWeapon() and ent2:IsWeapon() then
		return false
	elseif ent1:IsPlayer() and ent2:IsPlayer() then
		return false
	elseif table.HasValue(nocollide, ent1.ClassName) and table.HasValue(nocollide, ent2.ClassName) then
		return false
	else
		return true
	end
end

local meta = FindMetaTable("Player")
function meta:GetAFK()
	return self:GetDTBool(DT_BOOL_AFK)
end

function meta:GetTeamClass()
	return team.GetClass(self:Team())
end

function meta:StructCount(ent)
	i = 0
	for k,v in pairs(ents.FindByClass(ent)) do
		if (v:IsValid() && v.dt.Owner == self) then
			i = i+1
		end
	end
	return i
end

//needs revising
function GetDrugList()
	local sents = scripted_ents.GetList()
	
	local results = {}
	for classname, enttable in pairs(sents) do
		if enttable.Base == "base_drug" then
			table.insert(results, classname)
		end
	end
	table.sort(results)
	return results
end

function GetDrugTables()
	local sents = scripted_ents.GetSpawnable()
	
	local results = {}
	for sentclass, senttable in pairs(sents) do
		if senttable.Base == "base_drug" then
			results[sentclass] = senttable
		end
	end
	
	return results
end
//====================================

//by Nick Gammon
//http://www.gammon.com.au/forum/?id=7805
function util.commas(num)
  assert (type (num) == "number" or
          type (num) == "string")
  
  local result = ""

  local sign, before, after =
    string.match(tostring(num), "^([%+%-]?)(%d*)(%.?.*)$")

  while string.len(before) > 3 do
    result = "," .. string.sub(before, -3, -1) .. result
    before = string.sub(before, 1, -4)
  end

  return sign .. before .. result .. after
end
//============================================

//include and send player classes
for k, filename in pairs(file.FindInLua("RPDM/gamemode/classes/*.lua")) do
	if SERVER then
		include("classes/" .. filename)
		AddCSLuaFile("classes/" .. filename)
	else
		include("classes/" .. filename)
	end
end
